package stravel
import org.springframework.security.access.annotation.Secured

@Secured('isAuthenticated()')
class MyController {

	def springSecurityService
    def index() { }
	
	def comment(Long id){
		redirect(action:'index', controller:'review', id:id)
	}
	
	
	def addComment(Long id, String commentVal){
		println "id${id} commentVal:${commentVal} ${springSecurityService?.getCurrentUser()?.username}"
		
		User userInstance = User.get(springSecurityService?.getCurrentUser()?.id)
		if(commentVal){
			Hotel hotel = Hotel.get(id)
			def hotelCommentInstance = new HotelComment();
			hotelCommentInstance.hotel = hotel
			hotelCommentInstance.commentVal = commentVal
			hotelCommentInstance.user = userInstance
			hotelCommentInstance.createDate = new Date()
			if(hotelCommentInstance.save(flush:true)){
				println "save Comment"
			}else{
			println "error ${hotelCommentInstance.errors}"
			}
			
		}
		redirect(action:'index', controller:'review', id:id)
	}
}
